import {commonPath} from "@/utils/configPath.ts";

import {reqReject, reqResolve, resReject, resResolve} from "./interceptors.ts";
import axios from "axios";

interface configInterface {
    timeout: number
}

const defaultConfig: configInterface = {
    timeout: 30000
}

const createAxios = (options) => {
    const service = axios.create({
        ...defaultConfig,
        ...options
    })

    // 请求  拦截器
    service.interceptors.request.use(reqResolve, reqReject)

    // 响应  拦截器
    service.interceptors.response.use(resResolve, resReject)

    return service;
}

export const commonService = createAxios({
    baseURL: commonPath
})

